package unicom.hadoop.demo.service;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.springframework.stereotype.Service;

@Service("hadoopService")
public class HadoopService {
	public void helloworld(){
		System.out.println("Service : helloworld!");
	}
	
	public String copyFile(){
		try{
			Configuration conf=new Configuration();
	        FileSystem hdfs=FileSystem.get(conf);
	      //本地文件

	        Path src =new Path("D:\\360Downloads\\");

	        //HDFS为止

	        Path dst =new Path("/data/");
	        hdfs.copyFromLocalFile(src, dst);
	        System.out.println("Upload to"+conf.get("fs.default.name"));
	        FileStatus files[]=hdfs.listStatus(dst);

	        for(FileStatus file:files){

	            System.out.println(file.getPath());

	        }
		}catch(Exception e){
			
		}
		
        return "";
	}
}
